﻿<!-- 로그보기 -->
<!DOCTYPE html>
<html>
<body>
	<div id="logView" data-role="page" data-theme="a">
	<div data-role = "header">
		<a href="#" data-role="button" data-rel="back">이전</a>
		<h1>전단지</h1>
		<a href="#" data-role="button" id="del">지우기</a>
	</div>
	<div id="contentDiv" data-rol="content">
		<button onclick="getPhoto();">앨범에서 사진 선택</button>
		<div id="img"></div>
		<input type="text" name="n" class="input" id ="n"/> <!-- 동물이름  -->
		<input type="text" name="d" class="input" id ="d"/> <!-- 견종 -->
		<input type="text" name="o" class="input" id ="o"/> <!-- 색깔 -->
		<input type="tel" name="t" class="input" id ="t"/> <!-- 전번 -->
		<input type="text" name="m" class="input" id ="m"/>  <!-- 특이사항 -->
		<input type="number" name="c" class="input" id ="c"/> <!-- 사례금 -->
		<input type="text" name="mimetype" class="input" id ="mt" placeholder="분실일자" required="required"/>
		<input type="text" name="url" class="input" id ="mp" placeholder="분실장소" required="required" value="역삼동 멀티캠퍼스"/>
		<textarea name="payload" class="input" id="ms" placeholder="분실사유">분실사유</textarea>
		<textarea id="g" style="visibility:visible;"></textarea>
		
		
 <!-- 			나는 그냥 길을 가던 중이었는데 갑자기 괴한이 골목길에서 튀어나와 목줄을 칼로 끊고 개를 데리고
			그대로 도주함. 잃어버린 개는 100만원짜리 순종 잡종견으로 20살이 될 때까지 매우 아껴 기른 애견이므로 꼭 되찾고 싶습니다.
			만약 찾아만 주신다면 무슨 대가든 치를 터이니 부디 참작하시어 개를 찾아주시거나 납치범이 자수하여 광명을
			찾으면 좋겠습니다. 감사합니다.
 -->
		 <div id="map_cvs" style="width: 100%; height: 240px;"></div>
		<button onclick="sendPhoto();">찾아주세요!</button>
	</div>
	
	<script type="text/javascript">
		$('#logView').on('pageshow', function(){
			//url string
			var qString = fDecode(window.location.search.substring(1));
			var pid = fParamR('i', qString);
			$('#del').attr('onclick','fRemove('+pid+'); return false;'); 
			fRead(pid);
//			init();

			$('#mt').datetimepicker({
				 timepicker:false,
				 mask:true,
				 maxDate:0,
				 format:'Y/m/d' // '9999/19/39 29:59' - digit is the maximum possible for a cell
				});

		});

		/* 현재위치 가져오기 
	    var success = function(pos) {
	    	var currentLat = pos.coords.latitude;
	    	var currentLng = pos.coords.longitude;
	    	   var text = currentLat + ',' + currentLng + "\n";
	    	   alert('위치정보 확인 완료' + text);
	     	};
	    var fail = function(error) {
	    	alert('error occoured');
	        $("#cur_position").html("Error getting geolocation: " + error.code);
	        console.log("Error getting geolocation: code=" + error.code + " message=" + error.message);
	    };
		navigator.geolocation.getCurrentPosition(success, fail);
		 현재위치 가져오기 끝 */
		
		function onSuccess(position) {
		      currentLocation = position;
		      alert("onSuccess" + currentLocation);
		      if (!map) {
		         loadMapScript();
		      }
		   }
		   function onError(error) {
		      alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
		   }
/* 		      var infowindow = new google.maps.InfoWindow({
		         map : map,
		         position : latlng,
		         content : '자주 놀던 장소'
		      });
 */
		
		function getPhoto(){
			navigator.camera.getPicture(
					function(imageURI){
						var image = document.getElementById('image');
						image.style.display = 'block';
						image.src = imageURI;
					},
					function(message){
						alert('Failed Because : ' + message);
					},
					{
						quality : 50,
						destinationType : navigator.camera.DestinationType.FILE_URI,
						sourceType : navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
					}
			);
		}
 
		function sendPhoto(){
			var image = document.getElementById('image');
			var imageURI = image.src;
			//console.log(imageURI + "  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			var options = new FileUploadOptions();
			options.fileKey = "uploadImg";
			options.fileName = new Date().getTime();
			options.mimeType = "image/jpeg";
			var params = new Object();
			params.param0 = options.fileName;
			params.param1 = $("#n").val();
			params.param2 = $("#d").val();
			params.param3 = $("#o").val();
			params.param4 = $("#t").val();
			params.param5 = $("#m").val();
			params.param6 = $("#c").val();
			params.param7 = $("#mt").val();
			params.param8 = $("#mp").val();
			params.param9 = $("#ms").val();
			params.param10 = $("#g").val();
			options.params = params;
			
			var fileTransfer = new FileTransfer();
			fileTransfer.upload(
				imageURI,
				"http://70.12.110.62:8888/upload",
				function(response){
					alert("Code = " + response.responseCode + "\n" + "Response = " + response.response + "\n" + "Sent = " + response.bytesSent	);
//					$.mobile.changePage( "http://70.12.110.62:8888/sosList", "slideleft" );
					$.mobile.changePage( "index.html", "slideleft" );
					if(response.responseCode='200'){
						alert('SOS 등록 완료');
					}
				},
				function(error){//1.앱사진파일문제,2.서버경로문제,3.연결문제
					alert("Error Code = " + error.code);
				},
				options);
		}
		
	</script>
</div>
</body>
</html>